﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PraxisRent.Entities;
using System.Data;

namespace PraxisRent.Repository
{
    public class PagoRepository:MasterRepository,IPagoRepository
    {
        public List<PAGO> GetAllFromPago()
        {
            var query = from p in context.PAGOes
                        select p;
            return query.ToList();
        }

        public List<PAGO> GetAllFromPagoByIdCredito(int id)
        {
            var query = from p in context.PAGOes.Include("CREDITO")
                        where p.IdCredito.Equals(id)
                        select p;
            return query.ToList();
        }

        public PAGO GetAllFromPagoById(int id)
        {
            var query = from p in context.PAGOes
                        where p.Id.Equals(id)
                        select p;
            return query.SingleOrDefault();
        }

        public void AddPago(PAGO pago)
        {
            pago.CREDITO = null;

            context.PAGOes.Add(pago);
            context.SaveChanges();
        }

        public void UpdatePago(PAGO pago)
        {
            pago.CREDITO = null;

            context.Entry(pago).State = EntityState.Modified;
            context.SaveChanges();
        }

        public List<PAGO> GetAllFromPagoByIdCreditoAndCancelados(int id)
        {
            var query = from c in context.PAGOes.Include("CREDITO")
                        where c.IdCredito.Equals(id) && c.Cancelado == true
                        select c;
            return query.ToList();
        }
    }
}
